import {Injectable} from '@angular/core';
import {ConfigService} from './config.service';
import {environment} from '../../../environments/environment';

@Injectable({
    providedIn: 'root'
})
export class UrlService {

    path = 'assets/config/webconfig/webconfig.json';

    // 系统后端地址
    host: string;

    fastdfsAddress;

    // 文件存储路径
    fileStorePath;

    docServieIP;

    checkLisenceUrl;
    generateKeyUrl;
    registerUrl;

    constructor(
        private config: ConfigService,
    ) {
        let webConfig = this.config.getConfig(this.path);
        this.host = webConfig['HOST'];
        this.fastdfsAddress = webConfig['FastDFSAddress'];
        this.fileStorePath = webConfig['FileStorePath'];
        this.docServieIP = webConfig['DocServiceIP'];

        let copy = this.host.slice(0, this.host.lastIndexOf(':')) + ':65533';
        // let grantHost = webConfig['grantOrigin'] ? ? copy;
        // if (!environment.production) {
        //     //  调试环境，默认138
        //     grantHost = 'http://10.110.84.138:65533';
        // }
        // this.checkLisenceUrl = grantHost + '/checklisence';
        // this.generateKeyUrl = grantHost + '/generatekey';
        // this.registerUrl = grantHost + '/register';
    }

    // 直接拼简易url
    url(path) {
        return this.host + path;
    }

    // TODO 退出登陆
    // token验证不通过即退出
    public logout(res: any): any {

    }
}
